package com.example;

import com.sun.source.tree.NewArrayTree;

import java.security.PrivateKey;

public class MultiThreadShareData {
    public static void main(String[] args) {
        ShareData data = new ShareData();
        new Thread(data).start();
        new Thread(data).start();
    }
}

/**
 * 如果每个线程执行的代码相同，可以使用同一个Runnable对象，这个Runnable对象中有那个共享数据
 */
class ShareData implements Runnable{
    private int count =10;

    @Override
    public void run() {
        while(count>0){
            count--;
            System.out.println(count);
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
